package juc;

public class KuCunJUC
{
    //模拟有100件香蕉
    static int i = 5;
    //模拟多线程实现秒杀
    public static void main(String[] args) throws InterruptedException
    {
        //模拟两千只猴进行抢购
        for (int j = 0; j < 200; j++)
        {
            new Thread(()->{
                synchronized (KuCunJUC.class)
                {
                    if (i == 0)
                    {
                        System.out.println("抢购结束，没有商品鸟~~~~"+Thread.currentThread().getName());
                    }else
                    {
                        System.out.println(Thread.currentThread().getName()+"抢到了第"+(6-i)+"件商品");
                        i--;
                    }
                }

            },String.valueOf(j)).start();
        }
    }

}
